package me.leiusual.sharing.ui

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import me.leiusual.sharing.repository.AdRepository
import me.leiusual.sharing.repository.PlatformRepository
import me.leiusual.sharing.repository.model.Data
import me.leiusual.sharing.util.extension.toLiveData
import javax.inject.Inject

/**
 * Create by leiusual on 2018/7/15
 */
class StartViewModel @Inject constructor(
    platformRepository: PlatformRepository,
    private val adRepository: AdRepository
) : ViewModel() {

  val startCountDown = platformRepository.startCountDown()

  private val _adStart = MutableLiveData<Unit>()
  val adStart: LiveData<Data<String>> = Transformations.switchMap(_adStart) {
    adRepository.adStart().toLiveData()
  }

  fun adStart() {
    _adStart.value = Unit
  }
}